using System;
using System.Collections.Generic;

namespace wMobinium.core.test
{
    [NUnit.Framework.TestFixture]
    public class TestSuitesCompleteEventArgsTest
    {
        [NUnit.Framework.Test]
        public void EnsureSerializationWorks()
        {
            TestResult testResult = TestResult.NotifySuccess("ensureContactIsEqual", 0, 0);
            List<TestResult> testResults = new List<TestResult>();
            testResults.Add(testResult);

            TestSuitesCompleteEventArgs testSuitesCompleteEventArgs = new TestSuitesCompleteEventArgs(testResults);
            testSuitesCompleteEventArgs.TimeStamp = DateTime.Parse("Jan/01/2007");
            string serialized = testSuitesCompleteEventArgs.Serialize();
            Console.Out.WriteLine(serialized);
            NUnit.Framework.Assert.AreEqual(expectedOutput(), serialized);
        }

        [NUnit.Framework.Test]
        public void EnsureDeserializationWorks()
        {
            TestResult testResult = TestResult.NotifySuccess("ensureContactIsEqual", 0, 0);
            List<TestResult> testResults = new List<TestResult>();
            testResults.Add(testResult);

            TestSuitesCompleteEventArgs expectedTestSuitesCompleteEventArgs =
                new TestSuitesCompleteEventArgs(testResults);
            TestSuitesCompleteEventArgs actualTestSuitesCompleteEventArgs =
                TestSuitesCompleteEventArgs.Deserialize(expectedOutput());

            NUnit.Framework.Assert.AreEqual(expectedTestSuitesCompleteEventArgs, actualTestSuitesCompleteEventArgs);
        }

        public string expectedOutput()
        {
            return
                "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<TestSuitesCompleteEventArgs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" timestamp=\"2007-01-01T00:00:00\">\r\n  <testresults>\r\n    <testresult>\r\n      <name>ensureContactIsEqual</name>\r\n      <runstate id=\"-1\" value=\"Executed\" />\r\n      <resultstate id=\"0\" value=\"Success\" />\r\n      <failuresite id=\"0\" value=\"None\" />\r\n      <time>0</time>\r\n      <stacktrace />\r\n      <errormessage />\r\n      <assertcount>0</assertcount>\r\n    </testresult>\r\n  </testresults>\r\n</TestSuitesCompleteEventArgs>";
        }
    }
}